package _17_剑指Offer;

public class _49_剑指Offer丑数 {

    public static void main(String[] args) {

        _49_剑指Offer丑数 v = new _49_剑指Offer丑数();

        System.out.println(v.nthUglyNumber(10));

    }

    // 计算丑数
    public int nthUglyNumber(int n) {
        int[] results = new int[n];
        // 定义三个指针
        results[0] = 1;
        int point2 = 0, point3 = 0, point5 = 0, idx = 1;
        while (idx < n) {
            int value2 = results[point2] * 2;
            int value3 = results[point3] * 3;
            int value5 = results[point5] * 5;
            int min = Math.min(Math.min(value2, value3), value5);
            if (min == value2) point2++;
            if (min == value3) point3++;
            if (min == value5) point5++;
            results[idx++] = min;
        }
        return results[n - 1];
    }

}
